//
//  SSOrderListSubController.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/6/26.
//

import UIKit

import SwiftyJSON


class SSOrderListSubController: UIViewController {
    
    @IBOutlet weak var tableView: UITableView!
    
    var type = "0"//0全部 1待服务
    
    
    var items = [SSEmployeeOrder]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.register(UINib(nibName: "SSNewOrderCell", bundle: Bundle.init(for: SSNewOrderCell.self)), forCellReuseIdentifier: "SSNewOrderCell")
//        tableView.backgroundColor = UIColor(hex: "DFEFFE")
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        getBannerNetwork()
        
        self.tableView.es.addPullToRefresh {
            [unowned self] in
            self.tableView.es.stopPullToRefresh()
            getBannerNetwork()
            print("1233")
        }
    }
    
    //banner
    func getBannerNetwork() {
        let param = [
            "pageCurrent": "1",
            "pageSize": "100",
            "phoneNo": kUserPhone,
            "type": type
            
        ] as [String:AnyObject]
        
        
        SSProgressHUD.share.show()
        HttpConnectTools.share.request(urlString: APIUrl.share.getEmployeeOrder_URL, parameters: param) { (result, error) in
            if let _ = result{
                SSProgressHUD.share.dismiss()
                
                guard let banners = [SSEmployeeOrder].deserialize(from: result, designatedPath:"data.listOrder") else {
                    return
                }
                self.items = banners as! [SSEmployeeOrder]
                self.tableView.reloadData()
            }else{
            }
        }
    }
}

extension SSOrderListSubController: UITableViewDelegate, UITableViewDataSource
{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = SSOrderDetailController()
        vc.orderNo = self.items[indexPath.row].orderNo
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 190
    }
  
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SSNewOrderCell") as! SSNewOrderCell
        cell.resultClosure {
            self.getBannerNetwork()
        }
        cell.model = items[indexPath.row]
        return cell
    }
    
   
}

